'use strict';
const db = uniCloud.database()

exports.main = async (event, context) => {
  const { name } = event
  
  if (!name) {
    return {
      code: -1,
      msg: '缺少必要参数'
    }
  }
  
  try {
    const collection = db.collection('food-list')
    const res = await collection.where({
      name: name
    }).limit(1).get()
    
    return {
      code: 0,
      msg: 'success',
      data: res.data[0]
    }
  } catch(e) {
    return {
      code: -2,
      msg: '获取数据失败',
      error: e
    }
  }
}; 